<?php
/**
 * Desc: Service模板
 * User: zdb
 * Date: 2023/6/5
 * Time: 11:22
 */
namespace app\api\service\##package##;
use app\api\model\##package##\ExampleModel;

class ExampleService
{
    private $relateModel;
    public function __construct()
    {
        $this->relateModel = new ExampleModel();
    }

    public function getExampleList($data, $pageIndex, $pageSize)
    {
        $model = $this->relateModel;
        return $model->getListWithPage($data, $pageIndex, $pageSize);
    }

    public function getExampleOption($data)
    {
        $model = $this->relateModel;
        return $model->getListNoPage($data);
    }

    public function getExampleInfoById($id)
    {
        $model = $this->relateModel;
        return $model->findOneById($id);
    }

    public function getExampleInfoByCondition($condition)
    {
        $model = $this->relateModel;
        return $model->findOneByCondition($condition);
    }

    public function getExampleTotalNum($data)
    {
        $model = $this->relateModel;
        return $model->getTotalNum($data);
    }

    public function addExample($data)
    {
        $model = $this->relateModel;
        $res = $model->insertOne($data);
        if($res){
            $finalData = array_merge($data, array('new_id' => $res));
            return $finalData;
        }else{
            return array();
        }
    }

    public function addMultiExample($data)
    {
        $model = $this->relateModel;
        return $model->insertAll($data);
    }

    public function editExampleById($id, $data)
    {
        $model = $this->relateModel;
        return $model->updateOneById($id, $data);
    }

    public function editExampleByCondition($condition, $data)
    {
        $model = $this->relateModel;
        return $model->updateListByCondition($condition, $data);
    }

    public function editExampleByManyId($arrId, $data)
    {
        $model = $this->relateModel;
        return $model->updateListByManyId($arrId, $data);
    }

    public function deleteExampleById($id)
    {
        $model = $this->relateModel;
        return $model->removeOneById($id);
    }

    public function deleteExampleByManyId($arrId)
    {
        $model = $this->relateModel;
        return $model->removeListByManyId($arrId);
    }
}
